﻿@{
    ViewBag.Title = "Login";
    Layout = "~/Views/Master/_OuterLayout.cshtml";
}
@section headerscripts{
    <script type="text/javascript">
        $(document).ready(function () {

            $("#EmailTextbox").focus();

            //Functionality for pressing Enter
            $("#LoginBox").keydown(function (e) {
                if (e.keyCode == 13) {
                    $("#PasswordTextbox").blur();
                    $("#LoginButton").click();
                    return false;
                }
            });

            //Login button
            $("#LoginButton").bind("click", function (e) {
                $("#LoginBox").block({ message: "Authenticating...", fadeIn: 500 });

                //
                $.timer(500, function () {
                    var email = $("#EmailTextbox").val();
                    var password = $("#PasswordTextbox").val();
                    $.ajax({
                        type: "POST",
                        url: "/Login/CallLogin",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        data: JSON.stringify({ email: email, password: password }),
                        async: false,
                        success: function (response) {
                            if (response != null) {
                                window.location.href = response.Redirect;
                            }
                            else if (response == null) {
                                alert("Incorrect credentials");
                                $("#LoginBox").unblock();
                            }

                            
                        },
                        error: function (req, status, error) {
                            alert("Login failed !");
                            $("#LoginBox").unblock();
                        }
                    });
                });
            });


        });
    </script>
}
<div id="LoginBox" class="RoundedBox">
    <div class="BoxHeader">
        <div class="BoxInnerHeader">
            <span class="HeaderLabel">Login</span>
        </div>
    </div>
    <div class="BoxContent">
        <table>
            <tr>
                <td>
                    <span class="Label">Email</span>
                </td>
            </tr>
            <tr>
                <td>
                    <input class="Textbox" type="text" id="EmailTextbox" />
                </td>
            </tr>
            <tr>
                <td>
                    <span class="Label">Password</span>
                </td>
            </tr>
            <tr>
                <td>
                    <input class="Textbox" type="password" id="PasswordTextbox" />
                </td>
            </tr>
        </table>
    </div>
    <div class="BoxBottomActions">
        <div class="Button-Normal" id="LoginButton">
            <img src="../../Content/themes/base/images/Icons/Login.png" />
            <span>Log in</span>
        </div>
    </div>
    <div class="BoxFooter">
        <div class="BoxInnerFooter">
        </div>
    </div>
</div>
